
$(function() {
    $(".fecha").datepicker({dateFormat: 'yy-mm-dd'});
    $(".fechaMY").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, yearRange: '-100:+0'});
    $('.hora').timepicker({
        minuteStep: 1,
        showSeconds: true,
        showMeridian: false
    });
    $(".comboselect2").select2();
});

function NumCheck(e, field) {
    var key = e.keyCode ? e.keyCode : e.which;
    var regexp;
    if (key === 8)
        return true;
    if (key > 47 && key < 58) {
        if (field.value === "")
            return true;
        regexp = /.[0-9]{3}$/;
        return !(regexp.test(field.value));
    }
    if (key === 46) {
        if (field.value === "")
            return false;
        regexp = /^[0-9]+$/;
        return regexp.test(field.value);
    }
    return false;

}

function abrir(div, link) {
    $.ajax({
        url: link,
        contentType: "text/html; charset=UTF-8",
        success: function(data) {
            $('#' + div).html(data);
        }
    }
    );
}

function combo(url, id) {
    $.ajax({
        type: "POST",
        url: url,
        //data: { tipo: tipo }, //usarlo cuando se envía mediante POST
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            $(msg).each(function() {
                for (var i = 0; i < this.registros.length; i++) {
                    var option = $(document.createElement('option'));
                    option.text(this.registros[i].descripcion);
                    option.val(this.registros[i].codigo);
                    $("#" + id).append(option);
                }
            });
        }
    });
}

function ventana(id, width, height, modal, position) {
    $("#" + id).dialog({
        autoOpen: false,
        modal: modal,
        position: position,
        width: width,
        height: height,
        show: {
            effect: "drop",
            duration: 500
        },
        buttons: {
            "Cancel": function() {
                $(this).dialog("close");
            }
        }
    });
}